package org.jackysoft.entity;

import java.io.Serializable;
import java.util.Map;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.jackysoft.report.ItemUnit;

import com.google.common.collect.Maps;

/**
 * 
 * 军品产量月报表项目
 * 对应月份军品产量月快报
 * @author 屈甲康
 * 
 */
@MappedSuperclass
public abstract class AbstractItem implements Serializable, ItemUnit{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;	
		
	private String remark;	

	private boolean excluded = false;

	private Product host;
	
	private ProductType itemType = ProductType.常规产品;
	
	private Map<String,DataItem> dataItems = Maps.newHashMap();
	
	private boolean actioned = false;
	
	public AbstractItem() {
		
	}

	
	/**
	 * 系统标识
	 */

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @return the excluded
	 */
	public boolean isExcluded() {
		return excluded;
	}

	/**
	 * @param excluded
	 *            the excluded to set
	 */
	public void setExcluded(Boolean excluded) {
		if (excluded == null)
			this.excluded = false;
		else
			this.excluded = excluded;
	}
	

	public void setItemType(ProductType itemType) {
		this.itemType = itemType;
	}

	
	public ProductType getItemType() {
		return itemType;
	}

	public void setDataItems(Map<String,DataItem> dataItems) {
		this.dataItems = dataItems;
	}


	@OneToMany(orphanRemoval=true)
    @Cascade(value = {
    		org.hibernate.annotations.CascadeType.ALL   		
    })
	@JoinTable(name="item_dataitem",
                  joinColumns=@JoinColumn(name="item_id"),
                  inverseJoinColumns=@JoinColumn(name="dataitem_id"))
    @MapKeyJoinColumn(name="datalabel",referencedColumnName="label")
	@JSON(serialize=false)
	public Map<String,DataItem> getDataItems() {
		return dataItems;
	}


	@ManyToOne
	public Product getHost() {
		return host;
	}


	public void setHost(Product host) {
		this.host = host;
	}


	@Transient
	public boolean isActioned() {
		return actioned;
	}


	public void setActioned(boolean actioned) {
		this.actioned = actioned;
	}
	
	
}
